Skip to content

Conversation

@sherwinski
Copy link
Contributor

@sherwinski sherwinski commented Oct 28, 2025

Description

One Line Summary

Added flags to ensure addEventListener() only registers each native handler once per event type, eliminating unnecessary cordova.exec calls.

Details

Motivation

I noticed that we may be creating too many native handlers, once per each invocation of addEventListener(). This could cause a potential memory leak in the consuming applications.

Scope

Any addEventListener function across the InAppMessages, Notifications, User, and PushSubscription namespaces.

Testing

Unit testing

One tested added that ensures that cordova.exec is only called once, no matter how many event listeners are added.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

Added flags to ensure addEventListener() only registers each native
handler once per event type, eliminating unnecessary `cordova.exec` calls.

This fix is applied to the InAppMessages, Notifications, User, and PushSubscription namespaces.
@fadi-george fadi-george force-pushed the fg/more-tests branch 2 times, most recently from d608ec1 to 9d144c1 Compare October 28, 2025 18:23
@sherwinski
Copy link
Contributor Author

I'm not sure if this is a realistic concern but thought I'd raise it anyways for discussion.
I also looked into a way to remove a native handler when all event listeners were removed but couldn't figure out what API exists for that.

Base automatically changed from fg/more-tests to main October 28, 2025 19:33
@fadi-george fadi-george force-pushed the main branch 8 times, most recently from f9ef46e to 80ffffa Compare October 30, 2025 17:26
@fadi-george fadi-george requested a review from a team as a code owner October 30, 2025 18:20
@fadi-george fadi-george force-pushed the main branch 10 times, most recently from 3c70db9 to 0997dcf Compare October 30, 2025 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants